package com.wanxi.app.controller.api;

import com.wanxi.app.domain.vo.MyShoppingVo;
import com.wanxi.app.service.user.MyShoppingService;
import com.wanxi.product.service.api.result.CommonResult;
import com.wanxi.user.domain.dto.DelShoppingCartDto;
import com.wanxi.user.domain.dto.ShoppingCartDto;
import com.wanxi.user.domain.result.UserResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.math.BigDecimal;

/**
 * @Author:wgy
 * @Data：2022/1/13 14:00
 */
@RestController
@RequestMapping("app")
@Api(tags = "购物车")
public class MyShoppingApi {


    @Resource
    private MyShoppingService myShoppingService;

    /**
     * 查看购物车信息
     * @param userId 用户id
     * @return
     */
    @ApiOperation(value = "用户查看购物车")
    @GetMapping("findMyShopping")
    public CommonResult<MyShoppingVo> findMyShopping(long userId){
        return myShoppingService.findMyShopping(userId);
    }

    /**
     * 购物车加入商品
     *
     * @param productCartDto
     * @return
     */
    @ApiOperation(value = "购物车添加商品")
    @PostMapping("addCartProduct")
    public UserResult<Long> addCartProduct(ShoppingCartDto productCartDto) {

        return myShoppingService.addCartProduct(productCartDto);

    }

    /**
     * 清空购物车商品
     *
     * @param userId
     * @return
     */
    @ApiOperation(value = "用户清空购物车商品")
    @PutMapping("delCartProductAll")
    public UserResult<Boolean> delCartProductAll(long userId) {
        return myShoppingService.delCartProductAll(userId);
    }

    /**
     * 删除购物车商品
     *
     * @param shoppingCartDto
     * @return
     */
    @ApiOperation(value = "用户删除购物车商品")
    @PutMapping("delCartProduct")
    public UserResult<String> delShoppingCartByUserIdAndSkuId(DelShoppingCartDto shoppingCartDto) {
        return myShoppingService.delShoppingCartByUserIdAndSkuId(shoppingCartDto);
    }

    @ApiOperation(value = "计算购物车金额")
    @GetMapping("calculationAmount")
    public UserResult<BigDecimal> calculationAmount(Long userId) {
        return myShoppingService.calculationAmount(userId);
    }
}
